home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Book Chapters / 10 - Networking / NovelNetwar / appleEvents.c next >
Text File  |  1995-05-12  |  3KB  |  141 lines

  1. //    This module implements minimal support for Apple Events
  2.  
  3. //    Is it just me, or is it really a huge pain to do anything serious with Apple Events?
  4. //    Another program I've written uses AppleEvents to communicate with Eudora, and it nearly
  5. //    killed me to get it to work....  The AppleEvent documentation makes my head hurt.  =(
  6.  
  7.  
  8. #include "NovelNetwar.h"
  9.  
  10. #include <AppleEvents.h>
  11. #include <GestaltEqu.h>
  12.  
  13.  
  14. pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  15. pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  16. pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  17. pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  18.  
  19.  
  20.  
  21.  
  22.  
  23. void appleEventsInit(void)
  24. {
  25. OSErr        errCode;
  26. long        aLong;
  27. char        tempString[256];
  28.     
  29.     if (Gestalt(gestaltAppleEventsAttr, &aLong) == noErr)
  30.     {
  31.         errCode = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,AEOpenHandler, 0, FALSE);
  32.  
  33.         if (errCode != noErr) 
  34.         {
  35.             sprintf(tempString,"appleEventsInit: AEInstallEventHandler() error %d",errCode);
  36.                 
  37.             ErrorAlert(tempString);
  38.         }
  39.             
  40.         errCode = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,AEOpenDocHandler, 0, FALSE);
  41.  
  42.         if (errCode != noErr) 
  43.         {
  44.             sprintf(tempString,"appleEventsInit: AEInstallEventHandler() error %d",errCode);
  45.                 
  46.             ErrorAlert(tempString);
  47.         }
  48.         
  49.         errCode = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,AEQuitHandler, 0, FALSE);
  50.  
  51.         if (errCode != noErr) 
  52.         {
  53.             sprintf(tempString,"appleEventsInit: AEInstallEventHandler() error %d",errCode);
  54.                 
  55.             ErrorAlert(tempString);
  56.         }
  57.         
  58.         errCode = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,AEPrintHandler, 0, FALSE);
  59.  
  60.         if (errCode != noErr) 
  61.         {
  62.             sprintf(tempString,"appleEventsInit: AEInstallEventHandler() error %d",errCode);
  63.                 
  64.             ErrorAlert(tempString);
  65.         }
  66.     }
  67. }
  68.  
  69.  
  70.  
  71. void appleEventsStartup(void)
  72. {
  73.  
  74. }
  75.  
  76.  
  77.  
  78. void appleEventsShutDown(void)
  79. {
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. void DoHighLevel(EventRecord *AERecord)
  91. {
  92. int        errCode;
  93. char    tempString[256];
  94.  
  95.     errCode = AEProcessAppleEvent(AERecord);
  96.     
  97.     if (errCode != noErr)
  98.     {
  99.         sprintf(tempString,"DoHighLevel: AEProcessAppleEvent() error %d",errCode);
  100.         
  101. //        ErrorAlert(tempString);
  102.     }
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  110. {
  111.     
  112.     return(errAEEventNotHandled);
  113. }
  114.  
  115.  
  116.  
  117.  
  118. pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  119. {
  120.     
  121.     return(errAEEventNotHandled);
  122. }
  123.  
  124.  
  125.  
  126. pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  127. {
  128.     return(errAEEventNotHandled);
  129. }
  130.  
  131.  
  132.  
  133. pascal OSErr AEQuitHandler( AppleEvent *messagein, AppleEvent *reply, long refIn )
  134. {
  135.     alive = FALSE;
  136.     
  137.     return(noErr);
  138. }
  139.  
  140.  
  141.